<?php

/*  lamp-shade_0.1
 *  License: GNU GPL v3
 *  File: ./index.php
 *  Last Mod.:  02/11/11 by Werner
 *  Authors:    Werner Roets
 *              Frank Adrian
 *  Description:
 *  This is the main entry point for your website.
 */
   //pages
   require_once("./pages/home.php");
   require_once("./pages/cobolt.php");
   //aux pages
   require_once("./error_pages/not_found.php");
   require_once("./modules/standard/settings.php");
   require_once("./modules/standard/exceptions.php");
   
   class LampEngine
   {
      //All user pages
      public $home, $cobolt;
      
      public function RunSite()
      {
         $errors = 0;
         $all_pages = $this->MakePages();
         
         if(isset($_GET))
         {
            if(isset($_GET["page"]))
            {
               //identify the page!
               $found = 0;
               foreach($all_pages as $page)
               {
                  if($page->Name == $_GET["page"])
                  {
                     //theme the site
                     $page->Style = new Style(Settings::$master_css);
                     $page->Load($_GET, $_POST);
                     $found++;
                  }
               }
               if($found < 1)
               {
                  //The page doesn't exist e.g index.php?page=neverheardofthispage
                  $errors++;
               }
            }
            else
            {
               //The page was not specified
               header('Location: index.php?page=home');
            }
         }
         else
         {
            //query string is empty or wrong?
            $errors++;
            //header('Location: index.php?page=home');
         }
         if($errors>0)
         {
            $this->not_found->Style = new Style(Settings::$error_css);
            $this->not_found->Load($_GET,$_POST);
         }
      }
      
      //::::::::::::::::::::::::::
      // ## Initialize PAGES HERE ##
      //::::::::::::::::::::::::::
      private function MakePages()
      {
         $this->home = new HomePage("home");         
         $this->cobolt = new CoboltPage("cobolt");
         $this->not_found = new Not_Found("not_found");
         $page_array = array($this->home, $this->cobolt, $this->not_found);
         
         return $page_array;
      }
   }
   //entry point
   $lampshade = new LampEngine();
   $lampshade->RunSite();

    
    
?>
